package cn.itcast.user.contorller;

import cn.itcast.hmall.dto.common.ResultDTO;
import cn.itcast.hmall.pojo.user.Address;
import cn.itcast.hmall.pojo.user.User;
import cn.itcast.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/address")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据用户id 查询地址列表
     * @return
     */
    @GetMapping("/uid")
    public List<Address> queryAddressByUid(){
        return userService.queryAddressByUid();
    }


    /**
     * 根据id查询地址
     * @param addressId
     * @return
     */
    @GetMapping("/{addressId}")
    public Address queryAddressById(@PathVariable("addressId") Long addressId){
        return userService.queryAddressById(addressId);
    }

    /**
     * 根据id查询用户
     * @param uid
     * @return
     */
    @GetMapping("/user/{uid}")
    public User findUserById(@PathVariable("uid") Long uid){
        return userService.findUserById(uid);
    }

    /**
     * 根据id修改用户
     * @param user
     * @return
     */
    @PutMapping("/user")
    public ResultDTO updateUserById(@RequestBody User user){
        return userService.updateUserById(user);
    }


}
